using System;
using System.Collections.Generic;
using System.Text;

//business uses
using Adoor.DAL.Ouvrages;
using Adoor.DAL.Emprunts;

//ADOOR uses
using Adoor.Object.Disconnected; 


namespace Biblio.NUnit
{
	[TestFixture]
	public class TestDisconnected : BaseTest	
	{
        private ObjectContext myContext;

        [SetUp]
        public void Setup()
        {
            // Redirect the trace to the NUnit window
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out, "Console"));
        }


        [Test]
        public void MyDemoTest()
        {
            //create session from base class
            ObjectContext myContext = CreateContext();
            Bibliotheque biblio = myContext.LocalStorage.Create<Bibliotheque>();
            
            //adding a relationship
            int numeroExemplaire = 1664;
            Exemplaire exemplaire = myContext.LocalStorage.Create<Exemplaire>(numeroExemplaire);
            biblio.ExemplairesRendus.Add(exmplaire);
            
            myContext.Update();  

            //saving primarykey
            primaryKey = biblio.ToString();  
        }

        private string primaryKey;




        [Test]
        public void MyDeleteTest()
        {
            Bibliotheque biblio =  myContext.Find<Bibliotheque>(primaryKey);
            Exemplaire exemplaire = biblio.ExemplairesRendus[0];
            myContext.LocalStorage.Delete(biblio);
            myContext.LocalStorage.Delete(exemplaire);
            
            myContext.Update();  

        }

        [Test]
        public void MyCustomSelect()
        {
            string objectQuery = "Select Bibliotheque.Nom From Bibliotheque, Bibliotheque.ExemplairesRendus "
            + " WHERE ExemplairesRendus.Numero= ? ";

            System.Collections.ICollection col = myContext.Collect(objectQuery, 1664);
            
        }

	}
}
